<?php
/*
 * Created on 2011-4-27
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('display_errors',1);
 require_once('../phpQuery/phpQuery.php');


/*
phpQuery::$debug = false;

 $html = new DOMDocument();
 $html->loadHTMLFile('test2.html');
 $divs=$html->getElementsByTagName('body')->item(0)->childNodes;
 for($i=0;$i<$divs->length;$i++){
 	$d=$divs->item($i);
	echo $d->tagName."&type=".$d->nodeType."<br>";
 	//echo '<br>tag='.$d->tagName.';nodeType='.$d->nodeType.';value='.$d->textContent;
	if($d->nodeType==3){
		$n=$html->createElement('P',$d->nodeValue);
		$n->setAttribute('style','display:inline');
		$n->setAttribute('class','readability-styled');
		$d->parentNode->replaceChild($n,$d);
		//$d->tagName='p';
		
	}else{
		$d->setAttribute('sc',10+125);
	}
}

echo $html->saveHTML();
 exit;
//echo $divs->length;
  */

$p=phpQuery::newDocumentFile('test.html');
//$html=preg_replace('/^\s{0,}<!DOCTYPE html/i','',$p->htmlOuter());
$p->find('body')->html("");
//$dom->getElementsByTagName('body')->item(0)->nodeValue="";
$dom=$p->getDOMDocument();


$a="abcabcttt";
$a=preg_replace("/abc/i","",$a);
echo $a;
$span=$dom->createElement('span','abc');
$span2=$dom->createElement('span','efg');
echo $span->nodeName;
$dom->getElementsByTagName('body')->item(0)->appendChild($span);
$dom->getElementsByTagName('body')->item(0)->appendChild($span2);
$span2->nodeValue='ooo';
$cur=$dom->getElementsByTagName('body')->item(0)->firstChild;

while ($cur != null) {
			if ($cur->nodeType == 1) {
				// Remove style attribute(s) :
				if ($cur->getAttribute('class')!= "readability-styled") {
					$cur->removeAttribute("style");
				}
				$cur->setAttribute('score',10);
			}
			$cur = $cur->nextSibling;
		}
/*
for($i=0;$i<$lis->size();$i++){
	echo $i;
	$l=$p->find('li:eq('.$i.')');
	if(preg_match('/<font>/i',$l->html())){
		echo $i.'matched<br>';
		$l->replaceWith('<h2>bbb</h2>');
	}
	
}
*/
//echo '<br>'.$lis->size();



//$dom=$p->getDOMDocument();
//$dom->getElementsByTagName('li')->item(0)->nodeValue='ppppppppppppppppppppp';
//echo $dom->children();
//echo $lis instanceof phpQueryObject;
?>

<html>
<body>
	<textarea rows="20" cols="100"><?php echo $p->htmlOuter(); ?></textarea>
	<textarea rows="20" cols="100"><?php echo $dom->saveHTML(); ?></textarea>
</body>
</html>
